package com.fufu.thread;

import java.util.concurrent.*;

/**
 * 线程的优先级
 * @Author: 黑虎阿福
 * @Date: 2023/2/9 20:19
 * @Contact: hsf6661@163.com
 */
public class ThreadPriority {

    public static void main(String[] args) {
        //lambda语法创建thread线程
        Thread thread = new Thread(()->{
            for (int i = 0; i < 10; i++) {
                System.out.println("th:"+i);
            }
        });
        //lambda语法创建线程thread1
        Thread thread1 = new Thread(()->{
            for (int i = 0; i < 10; i++) {
                System.out.println("th--->:"+i);
            }
        });
        //设置线程的优先级，window默认优先级为5，优先级越高，被执行的概率越大，但不代表一定会被执行
        thread.setPriority(5);
        thread1.setPriority(7);
        //启动线程
        thread.start();
        thread1.start();


        /* jdk1.8以后删除了ThreadFactoryBuilder类
        ThreadFactory namedThreadFactory = new ThreadFactoryBuilder()
                    .setNameFormat("demo-pool-%d").build();
         */
//        ExecutorService singleThreadPool = new ThreadPoolExecutor(1, 1,
//                0L, TimeUnit.MILLISECONDS,
//                new LinkedBlockingQueue<Runnable>(1024), Executors.defaultThreadFactory(), new ThreadPoolExecutor.AbortPolicy());
//
//        singleThreadPool.execute(()-> System.out.println(Thread.currentThread().getName()));
//        singleThreadPool.shutdown();
    }
}
